/* Copyright (c) 2025 Beijing Semidrive Technology Corporation
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/** *****************************************************************************************************
 * \file     McuExt_Vd.h                                                                           *
 * \brief    AUTOSAR 4.3.1 MCAL Mcu Driver                                                              *
 *                                                                                                      *
 * <table>                                                                                              *
 * <tr><th>Date           <th>Version                                                                   *
 * <tr><td>2023/08/29     <td>1.0U.0U                                                                   *
 * </table>                                                                                             *
 *******************************************************************************************************/

#ifndef VD_H
#define VD_H

#ifdef __cplusplus
extern "C" {
#endif

/********************************************************************************************************
 *                                      Include header files                                            *
 *******************************************************************************************************/
#include "regs_base.h"
#include "lld_platform.h"
/********************************************************************************************************
 *                                      Macro definition                                                *
 *******************************************************************************************************/
#define MCUEXT_APB_VD_SF_BASE           APB_VD_SF_BASE

#define MCUEXT_APB_VD_LP_BASE           APB_VD_LP_BASE
/** \brief VD threshold error offset*/
#define VD_ERRTHRESHOLD_OFFSET  (4u)
/** \brief VD threshold max value*/
#define VD_THRESHOLD_MAX  (0xFu)
/** \brief VD threshold min value*/
#define VD_THRESHOLD_MIN  (0x1u)
/** \brief VD threshold max value*/
#define VD_WARNINGTHRESHOLD_MASK  (0xFu)

/** \brief McuExt VD Driver is NOT initialized. */
#define VD_UNINIT                                                      (uint8_t)(0x00U)

/** \brief  McuExt VD Driver is initialized. */
#define VD_INIT                                                        (uint8_t)(0x01U)

#if defined (CFG_PLATFORM_MCAL)
#include "McuExt_Fault.h"
#include "Mcal_MemLibc.h"
#define VD_SAFETY_INTERRUPT_ENABLE                                            (MCUEXT_VD_SAFETY_INTERRUPT_ENABLE == STD_ON)
#define VD_ENABLE_NOTIFICATION_API                                            (MCUEXT_VD_ENABLE_NOTIFICATION_API == STD_ON)
#define VD_ND_MODE                                                            (MCUEXT_VD_ND_CFG == STD_ON)
#define VD_UDELAY(us)                                                         Mcal_udelay(us)
#define VD_MEM_COPY                                                           Mcal_MemCpy
/** \brief  ERROR:Error due to vd error injection failed. */
#define MCUEXT_E_VD_ERROR_INJECT_FAILED                                       (lld_status_t)(0x90U)

#define VD_E_OK                                                               E_OK
#define VD_E_ERROR_INJECT_FAILED                                              MCUEXT_E_VD_ERROR_INJECT_FAILED

#define VD_E_PARAM_POINTER                                                    MCUEXT_E_PARAM_POINTER

#define VD_E_ATE_ANALOG_TRIM_FAIL                                             MCUEXT_E_ATE_ANALOG_TRIM_FAIL
#elif defined (CFG_PLATFORM_SSDK)
#include <string.h>
#define VD_SAFETY_INTERRUPT_ENABLE                                            (CONFIG_VD_SAFETY_INTERRUPT)
#define VD_ENABLE_NOTIFICATION_API                                            (CONFIG_VD_NOTIFICATION)
#define VD_ND_MODE                                                            (CONFIG_VD_ND_MODE)
#define VD_UDELAY(us)                                                         udelay(us)
#define VD_MEM_COPY                                                           memcpy
#define VD_E_OK                                                               SDRV_STATUS_OK
#define VD_E_ERROR_INJECT_FAILED                                              SDRV_ERROR_STATUS(SDRV_STATUS_GROUP_VD, 1)
#define VD_E_ATE_ANALOG_TRIM_FAIL                                             SDRV_ERROR_STATUS(SDRV_STATUS_GROUP_VD, 2)
#define VdHookBegin_Vd_IrqHandler(id)
#define VdHookEnd_Vd_IrqHandler(id)
#define VdHookBegin_Vd_IrqHandlerPhase0()
#define VdHookBegin_Vd_TrimThresholdCalculate()
#define VdHookBegin_Vd_ClrIntState(id)
#define VdHookBegin_Vd_VinsetThresholdMap()
#define VdHookEnd_Vd_VinsetThresholdMap(id)
#define VdHookBegin_Vd_Init()
#if VD_SAFETY_INTERRUPT_ENABLE
#define VdHookBegin_Vd_ErrorInjection()
#endif
#else
#error "Undefined macros CFG_PLATFORM_MCAL or CFG_PLATFORM_SSDK"
#endif /** #if defined (CFG_PLATFORM_MCAL) */
/********************************************************************************************************
 *                                     VD register Macro definition                                     *
 *******************************************************************************************************/

#define VOLT_SEL_OFF(n)  (0x0U + (4U*(n)))

#define FM_VOLT_SEL_VD_VIN3_SEL  ((uint32_t)0xffU << 24U)
#define FV_VOLT_SEL_VD_VIN3_SEL(v) \
  (((uint32_t)(v) << 24U) & FM_VOLT_SEL_VD_VIN3_SEL)
#define GFV_VOLT_SEL_VD_VIN3_SEL(v) \
  (((uint32_t)(v) & FM_VOLT_SEL_VD_VIN3_SEL) >> 24U)

#define FM_VOLT_SEL_VD_VIN2_SEL  ((uint32_t)0xffU << 16U)
#define FV_VOLT_SEL_VD_VIN2_SEL(v) \
  (((uint32_t)(v) << 16U) & FM_VOLT_SEL_VD_VIN2_SEL)
#define GFV_VOLT_SEL_VD_VIN2_SEL(v) \
  (((uint32_t)(v) & FM_VOLT_SEL_VD_VIN2_SEL) >> 16U)

#define FM_VOLT_SEL_VD_VIN1_SEL  ((uint32_t)0xffU << 8U)
#define FV_VOLT_SEL_VD_VIN1_SEL(v) \
  (((uint32_t)(v) << 8U) & FM_VOLT_SEL_VD_VIN1_SEL)
#define GFV_VOLT_SEL_VD_VIN1_SEL(v) \
  (((uint32_t)(v) & FM_VOLT_SEL_VD_VIN1_SEL) >> 8U)

#define FM_VOLT_SEL_VD_VIN0_SEL  ((uint32_t)0xffU << 0U)
#define FV_VOLT_SEL_VD_VIN0_SEL(v) \
  (((uint32_t)(v) << 0U) & FM_VOLT_SEL_VD_VIN0_SEL)
#define GFV_VOLT_SEL_VD_VIN0_SEL(v) \
  (((uint32_t)(v) & FM_VOLT_SEL_VD_VIN0_SEL) >> 0U)

#define CFG_OV_THRE_OFF(n)  (0x4U + (4U*(n)))

#define FM_CFG_OV_THRE_VD_VIN3_OV_TH  ((uint32_t)0xffU << 24U)
#define FV_CFG_OV_THRE_VD_VIN3_OV_TH(v) \
  (((uint32_t)(v) << 24U) & FM_CFG_OV_THRE_VD_VIN3_OV_TH)
#define GFV_CFG_OV_THRE_VD_VIN3_OV_TH(v) \
  (((uint32_t)(v) & FM_CFG_OV_THRE_VD_VIN3_OV_TH) >> 24U)

#define FM_CFG_OV_THRE_VD_VIN2_OV_TH  ((uint32_t)0xffU << 16U)
#define FV_CFG_OV_THRE_VD_VIN2_OV_TH(v) \
  (((uint32_t)(v) << 16U) & FM_CFG_OV_THRE_VD_VIN2_OV_TH)
#define GFV_CFG_OV_THRE_VD_VIN2_OV_TH(v) \
  (((uint32_t)(v) & FM_CFG_OV_THRE_VD_VIN2_OV_TH) >> 16U)

#define FM_CFG_OV_THRE_VD_VIN1_OV_TH  ((uint32_t)0xffU << 8U)
#define FV_CFG_OV_THRE_VD_VIN1_OV_TH(v) \
  (((uint32_t)(v) << 8U) & FM_CFG_OV_THRE_VD_VIN1_OV_TH)
#define GFV_CFG_OV_THRE_VD_VIN1_OV_TH(v) \
  (((uint32_t)(v) & FM_CFG_OV_THRE_VD_VIN1_OV_TH) >> 8U)

#define FM_CFG_OV_THRE_VD_VIN0_OV_TH  ((uint32_t)0xffU << 0U)
#define FV_CFG_OV_THRE_VD_VIN0_OV_TH(v) \
  (((uint32_t)(v) << 0U) & FM_CFG_OV_THRE_VD_VIN0_OV_TH)
#define GFV_CFG_OV_THRE_VD_VIN0_OV_TH(v) \
  (((uint32_t)(v) & FM_CFG_OV_THRE_VD_VIN0_OV_TH) >> 0U)

#define CFG_UV_THRE_OFF(n)  (0x8U + (4U*(n)))

#define FM_CFG_UV_THRE_VD_VIN3_UV_TH  ((uint32_t)0xffU << 24U)
#define FV_CFG_UV_THRE_VD_VIN3_UV_TH(v) \
  (((uint32_t)(v) << 24U) & FM_CFG_UV_THRE_VD_VIN3_UV_TH)
#define GFV_CFG_UV_THRE_VD_VIN3_UV_TH(v) \
  (((uint32_t)(v) & FM_CFG_UV_THRE_VD_VIN3_UV_TH) >> 24U)

#define FM_CFG_UV_THRE_VD_VIN2_UV_TH  ((uint32_t)0xffU << 16U)
#define FV_CFG_UV_THRE_VD_VIN2_UV_TH(v) \
  (((uint32_t)(v) << 16U) & FM_CFG_UV_THRE_VD_VIN2_UV_TH)
#define GFV_CFG_UV_THRE_VD_VIN2_UV_TH(v) \
  (((uint32_t)(v) & FM_CFG_UV_THRE_VD_VIN2_UV_TH) >> 16U)

#define FM_CFG_UV_THRE_VD_VIN1_UV_TH  ((uint32_t)0xffU << 8U)
#define FV_CFG_UV_THRE_VD_VIN1_UV_TH(v) \
  (((uint32_t)(v) << 8U) & FM_CFG_UV_THRE_VD_VIN1_UV_TH)
#define GFV_CFG_UV_THRE_VD_VIN1_UV_TH(v) \
  (((uint32_t)(v) & FM_CFG_UV_THRE_VD_VIN1_UV_TH) >> 8U)

#define FM_CFG_UV_THRE_VD_VIN0_UV_TH  ((uint32_t)0xffU << 0U)
#define FV_CFG_UV_THRE_VD_VIN0_UV_TH(v) \
  (((uint32_t)(v) << 0U) & FM_CFG_UV_THRE_VD_VIN0_UV_TH)
#define GFV_CFG_UV_THRE_VD_VIN0_UV_TH(v) \
  (((uint32_t)(v) & FM_CFG_UV_THRE_VD_VIN0_UV_TH) >> 0U)

#define CFG_COM_OFF  0xcU

#define FM_CFG_COM_VD_REG_0  ((uint32_t)0xffU << 0U)
#define FV_CFG_COM_VD_REG_0(v) \
  (((uint32_t)(v) << 0U) & FM_CFG_COM_VD_REG_0)
#define GFV_CFG_COM_VD_REG_0(v) \
  (((uint32_t)(v) & FM_CFG_COM_VD_REG_0) >> 0U)

#define CFG_FILT_OFF  0x10U

#define BM_CFG_FILT_CFG_EN  ((uint32_t)0x01U << 16U)

#define FM_CFG_FILT_CFG_SI  ((uint32_t)0xffU << 8U)
#define FV_CFG_FILT_CFG_SI(v) \
  (((uint32_t)(v) << 8U) & FM_CFG_FILT_CFG_SI)
#define GFV_CFG_FILT_CFG_SI(v) \
  (((uint32_t)(v) & FM_CFG_FILT_CFG_SI) >> 8U)

#define FM_CFG_FILT_CFG_RFB  ((uint32_t)0xfU << 4U)
#define FV_CFG_FILT_CFG_RFB(v) \
  (((uint32_t)(v) << 4U) & FM_CFG_FILT_CFG_RFB)
#define GFV_CFG_FILT_CFG_RFB(v) \
  (((uint32_t)(v) & FM_CFG_FILT_CFG_RFB) >> 4U)

#define FM_CFG_FILT_CFG_FFB  ((uint32_t)0xfU << 0U)
#define FV_CFG_FILT_CFG_FFB(v) \
  (((uint32_t)(v) << 0U) & FM_CFG_FILT_CFG_FFB)
#define GFV_CFG_FILT_CFG_FFB(v) \
  (((uint32_t)(v) & FM_CFG_FILT_CFG_FFB) >> 0U)

#define CFG_MSK_CNT_OFF  0x14U

#define FM_CFG_MSK_CNT_CNT  ((uint32_t)0xffU << 0U)
#define FV_CFG_MSK_CNT_CNT(v) \
  (((uint32_t)(v) << 0U) & FM_CFG_MSK_CNT_CNT)
#define GFV_CFG_MSK_CNT_CNT(v) \
  (((uint32_t)(v) & FM_CFG_MSK_CNT_CNT) >> 0U)

#define VD_SELFTEST_MODE_OFF  0x18U

#define FUNC_STAT_OFF  0x1cU

#define BM_FUNC_STAT_VIN3_OV_ERR  ((uint32_t)0x01U << 15U)

#define BM_FUNC_STAT_VIN2_OV_ERR  ((uint32_t)0x01U << 14U)

#define BM_FUNC_STAT_VIN1_OV_ERR  ((uint32_t)0x01U << 13U)

#define BM_FUNC_STAT_VIN0_OV_ERR  ((uint32_t)0x01U << 12U)

#define BM_FUNC_STAT_VIN3_OV_WARN  ((uint32_t)0x01U << 11U)

#define BM_FUNC_STAT_VIN2_OV_WARN  ((uint32_t)0x01U << 10U)

#define BM_FUNC_STAT_VIN1_OV_WARN  ((uint32_t)0x01U << 9U)

#define BM_FUNC_STAT_VIN0_OV_WARN  ((uint32_t)0x01U << 8U)

#define BM_FUNC_STAT_VIN3_UV_ERR  ((uint32_t)0x01U << 7U)

#define BM_FUNC_STAT_VIN2_UV_ERR  ((uint32_t)0x01U << 6U)

#define BM_FUNC_STAT_VIN1_UV_ERR  ((uint32_t)0x01U << 5U)

#define BM_FUNC_STAT_VIN0_UV_ERR  ((uint32_t)0x01U << 4U)

#define BM_FUNC_STAT_VIN3_UV_WARN  ((uint32_t)0x01U << 3U)

#define BM_FUNC_STAT_VIN2_UV_WARN  ((uint32_t)0x01U << 2U)

#define BM_FUNC_STAT_VIN1_UV_WARN  ((uint32_t)0x01U << 1U)

#define BM_FUNC_STAT_VIN0_UV_WARN  ((uint32_t)0x01U << 0U)

#define FUNC_STAT_EN_OFF  0x20U

#define BM_FUNC_STAT_EN_VIN3_OV_ERR  ((uint32_t)0x01U << 15U)

#define BM_FUNC_STAT_EN_VIN2_OV_ERR  ((uint32_t)0x01U << 14U)

#define BM_FUNC_STAT_EN_VIN1_OV_ERR  ((uint32_t)0x01U << 13U)

#define BM_FUNC_STAT_EN_VIN0_OV_ERR  ((uint32_t)0x01U << 12U)

#define BM_FUNC_STAT_EN_VIN3_OV_WARN  ((uint32_t)0x01U << 11U)

#define BM_FUNC_STAT_EN_VIN2_OV_WARN  ((uint32_t)0x01U << 10U)

#define BM_FUNC_STAT_EN_VIN1_OV_WARN  ((uint32_t)0x01U << 9U)

#define BM_FUNC_STAT_EN_VIN0_OV_WARN  ((uint32_t)0x01U << 8U)

#define BM_FUNC_STAT_EN_VIN3_UV_ERR  ((uint32_t)0x01U << 7U)

#define BM_FUNC_STAT_EN_VIN2_UV_ERR  ((uint32_t)0x01U << 6U)

#define BM_FUNC_STAT_EN_VIN1_UV_ERR  ((uint32_t)0x01U << 5U)

#define BM_FUNC_STAT_EN_VIN0_UV_ERR  ((uint32_t)0x01U << 4U)

#define BM_FUNC_STAT_EN_VIN3_UV_WARN  ((uint32_t)0x01U << 3U)

#define BM_FUNC_STAT_EN_VIN2_UV_WARN  ((uint32_t)0x01U << 2U)

#define BM_FUNC_STAT_EN_VIN1_UV_WARN  ((uint32_t)0x01U << 1U)

#define BM_FUNC_STAT_EN_VIN0_UV_WARN  ((uint32_t)0x01U << 0U)

#define FUNC_INT_SIG_EN_OFF  0x24U

#define BM_FUNC_INT_SIG_EN_VIN3_OV_ERR  ((uint32_t)0x01U << 15U)

#define BM_FUNC_INT_SIG_EN_VIN2_OV_ERR  ((uint32_t)0x01U << 14U)

#define BM_FUNC_INT_SIG_EN_VIN1_OV_ERR  ((uint32_t)0x01U << 13U)

#define BM_FUNC_INT_SIG_EN_VIN0_OV_ERR  ((uint32_t)0x01U << 12U)

#define BM_FUNC_INT_SIG_EN_VIN3_OV_WARN  ((uint32_t)0x01U << 11U)

#define BM_FUNC_INT_SIG_EN_VIN2_OV_WARN  ((uint32_t)0x01U << 10U)

#define BM_FUNC_INT_SIG_EN_VIN1_OV_WARN  ((uint32_t)0x01U << 9U)

#define BM_FUNC_INT_SIG_EN_VIN0_OV_WARN  ((uint32_t)0x01U << 8U)

#define BM_FUNC_INT_SIG_EN_VIN3_UV_ERR  ((uint32_t)0x01U << 7U)

#define BM_FUNC_INT_SIG_EN_VIN2_UV_ERR  ((uint32_t)0x01U << 6U)

#define BM_FUNC_INT_SIG_EN_VIN1_UV_ERR  ((uint32_t)0x01U << 5U)

#define BM_FUNC_INT_SIG_EN_VIN0_UV_ERR  ((uint32_t)0x01U << 4U)

#define BM_FUNC_INT_SIG_EN_VIN3_UV_WARN  ((uint32_t)0x01U << 3U)

#define BM_FUNC_INT_SIG_EN_VIN2_UV_WARN  ((uint32_t)0x01U << 2U)

#define BM_FUNC_INT_SIG_EN_VIN1_UV_WARN  ((uint32_t)0x01U << 1U)

#define BM_FUNC_INT_SIG_EN_VIN0_UV_WARN  ((uint32_t)0x01U << 0U)

#define FUNC_COR_SIG_EN_OFF  0x28U

#define BM_FUNC_COR_SIG_EN_VIN3_OV_ERR  ((uint32_t)0x01U << 15U)

#define BM_FUNC_COR_SIG_EN_VIN2_OV_ERR  ((uint32_t)0x01U << 14U)

#define BM_FUNC_COR_SIG_EN_VIN1_OV_ERR  ((uint32_t)0x01U << 13U)

#define BM_FUNC_COR_SIG_EN_VIN0_OV_ERR  ((uint32_t)0x01U << 12U)

#define BM_FUNC_COR_SIG_EN_VIN3_OV_WRAN  ((uint32_t)0x01U << 11U)

#define BM_FUNC_COR_SIG_EN_VIN2_OV_WRAN  ((uint32_t)0x01U << 10U)

#define BM_FUNC_COR_SIG_EN_VIN1_OV_WRAN  ((uint32_t)0x01U << 9U)

#define BM_FUNC_COR_SIG_EN_VIN0_OV_WRAN  ((uint32_t)0x01U << 8U)

#define BM_FUNC_COR_SIG_EN_VIN3_UV_ERR  ((uint32_t)0x01U << 7U)

#define BM_FUNC_COR_SIG_EN_VIN2_UV_ERR  ((uint32_t)0x01U << 6U)

#define BM_FUNC_COR_SIG_EN_VIN1_UV_ERR  ((uint32_t)0x01U << 5U)

#define BM_FUNC_COR_SIG_EN_VIN0_UV_ERR  ((uint32_t)0x01U << 4U)

#define BM_FUNC_COR_SIG_EN_VIN3_UV_WRAN  ((uint32_t)0x01U << 3U)

#define BM_FUNC_COR_SIG_EN_VIN2_UV_WRAN  ((uint32_t)0x01U << 2U)

#define BM_FUNC_COR_SIG_EN_VIN1_UV_WRAN  ((uint32_t)0x01U << 1U)

#define BM_FUNC_COR_SIG_EN_VIN0_UV_WRAN  ((uint32_t)0x01U << 0U)

#define FUNC_UNC_SIG_EN_OFF  0x2cU

#define BM_FUNC_UNC_SIG_EN_VIN3_OV_ERR  ((uint32_t)0x01U << 15U)

#define BM_FUNC_UNC_SIG_EN_VIN2_OV_ERR  ((uint32_t)0x01U << 14U)

#define BM_FUNC_UNC_SIG_EN_VIN1_OV_ERR  ((uint32_t)0x01U << 13U)

#define BM_FUNC_UNC_SIG_EN_VIN0_OV_ERR  ((uint32_t)0x01U << 12U)

#define BM_FUNC_UNC_SIG_EN_VIN3_OV_WRAN  ((uint32_t)0x01U << 11U)

#define BM_FUNC_UNC_SIG_EN_VIN2_OV_WRAN  ((uint32_t)0x01U << 10U)

#define BM_FUNC_UNC_SIG_EN_VIN1_OV_WRAN  ((uint32_t)0x01U << 9U)

#define BM_FUNC_UNC_SIG_EN_VIN0_OV_WRAN  ((uint32_t)0x01U << 8U)

#define BM_FUNC_UNC_SIG_EN_VIN3_UV_ERR  ((uint32_t)0x01U << 7U)

#define BM_FUNC_UNC_SIG_EN_VIN2_UV_ERR  ((uint32_t)0x01U << 6U)

#define BM_FUNC_UNC_SIG_EN_VIN1_UV_ERR  ((uint32_t)0x01U << 5U)

#define BM_FUNC_UNC_SIG_EN_VIN0_UV_ERR  ((uint32_t)0x01U << 4U)

#define BM_FUNC_UNC_SIG_EN_VIN3_UV_WRAN  ((uint32_t)0x01U << 3U)

#define BM_FUNC_UNC_SIG_EN_VIN2_UV_WRAN  ((uint32_t)0x01U << 2U)

#define BM_FUNC_UNC_SIG_EN_VIN1_UV_WRAN  ((uint32_t)0x01U << 1U)

#define BM_FUNC_UNC_SIG_EN_VIN0_UV_WRAN  ((uint32_t)0x01U << 0U)

#define FUNC_STAT_CLR_OFF  0x30U

#define BM_FUNC_STAT_CLR_VIN3_OV_ERR  ((uint32_t)0x01U << 15U)

#define BM_FUNC_STAT_CLR_VIN2_OV_ERR  ((uint32_t)0x01U << 14U)

#define BM_FUNC_STAT_CLR_VIN1_OV_ERR  ((uint32_t)0x01U << 13U)

#define BM_FUNC_STAT_CLR_VIN0_OV_ERR  ((uint32_t)0x01U << 12U)

#define BM_FUNC_STAT_CLR_VIN3_OV_WARN  ((uint32_t)0x01U << 11U)

#define BM_FUNC_STAT_CLR_VIN2_OV_WARN  ((uint32_t)0x01U << 10U)

#define BM_FUNC_STAT_CLR_VIN1_OV_WARN  ((uint32_t)0x01U << 9U)

#define BM_FUNC_STAT_CLR_VIN0_OV_WARN  ((uint32_t)0x01U << 8U)

#define BM_FUNC_STAT_CLR_VIN3_UV_ERR  ((uint32_t)0x01U << 7U)

#define BM_FUNC_STAT_CLR_VIN2_UV_ERR  ((uint32_t)0x01U << 6U)

#define BM_FUNC_STAT_CLR_VIN1_UV_ERR  ((uint32_t)0x01U << 5U)

#define BM_FUNC_STAT_CLR_VIN0_UV_ERR  ((uint32_t)0x01U << 4U)

#define BM_FUNC_STAT_CLR_VIN3_UV_WARN  ((uint32_t)0x01U << 3U)

#define BM_FUNC_STAT_CLR_VIN2_UV_WARN  ((uint32_t)0x01U << 2U)

#define BM_FUNC_STAT_CLR_VIN1_UV_WARN  ((uint32_t)0x01U << 1U)

#define BM_FUNC_STAT_CLR_VIN0_UV_WARN  ((uint32_t)0x01U << 0U)

#define FUNC_DY_STAT_OFF  0x34U

#define BM_FUNC_DY_STAT_VIN3_OV_ERR  ((uint32_t)0x01U << 15U)

#define BM_FUNC_DY_STAT_VIN2_OV_ERR  ((uint32_t)0x01U << 14U)

#define BM_FUNC_DY_STAT_VIN1_OV_ERR  ((uint32_t)0x01U << 13U)

#define BM_FUNC_DY_STAT_VIN0_OV_ERR  ((uint32_t)0x01U << 12U)

#define BM_FUNC_DY_STAT_VIN3_OV_WRAN  ((uint32_t)0x01U << 11U)

#define BM_FUNC_DY_STAT_VIN2_OV_WRAN  ((uint32_t)0x01U << 10U)

#define BM_FUNC_DY_STAT_VIN1_OV_WRAN  ((uint32_t)0x01U << 9U)

#define BM_FUNC_DY_STAT_VIN0_OV_WARN  ((uint32_t)0x01U << 8U)

#define BM_FUNC_DY_STAT_VIN3_UV_ERR  ((uint32_t)0x01U << 7U)

#define BM_FUNC_DY_STAT_VIN2_UV_ERR  ((uint32_t)0x01U << 6U)

#define BM_FUNC_DY_STAT_VIN1_UV_ERR  ((uint32_t)0x01U << 5U)

#define BM_FUNC_DY_STAT_VIN0_UV_ERR  ((uint32_t)0x01U << 4U)

#define BM_FUNC_DY_STAT_VIN3_UV_WARN  ((uint32_t)0x01U << 3U)

#define BM_FUNC_DY_STAT_VIN2_UV_WARN  ((uint32_t)0x01U << 2U)

#define BM_FUNC_DY_STAT_VIN1_UV_WARN  ((uint32_t)0x01U << 1U)

#define BM_FUNC_DY_STAT_VIN0_UV_WARN  ((uint32_t)0x01U << 0U)

#define FUNC_HYST_SAT_OFF  0x38U

#define BM_FUNC_HYST_SAT_VIN3_OV_HYST  ((uint32_t)0x01U << 7U)

#define BM_FUNC_HYST_SAT_VIN2_OV_HYST  ((uint32_t)0x01U << 6U)

#define BM_FUNC_HYST_SAT_VIN1_OV_HYST  ((uint32_t)0x01U << 5U)

#define BM_FUNC_HYST_SAT_VIN0_OV_HYST  ((uint32_t)0x01U << 4U)

#define BM_FUNC_HYST_SAT_VIN3_UV_HYST  ((uint32_t)0x01U << 3U)

#define BM_FUNC_HYST_SAT_VIN2_UV_HYST  ((uint32_t)0x01U << 2U)

#define BM_FUNC_HYST_SAT_VIN1_UV_HYST  ((uint32_t)0x01U << 1U)

#define BM_FUNC_HYST_SAT_VIN0_UV_HYST  ((uint32_t)0x01U << 0U)

#define FUNC_STAT_CHK_OFF  0x3cU

#define BM_FUNC_STAT_CHK_VIN3_OV_CHK  ((uint32_t)0x01U << 7U)

#define BM_FUNC_STAT_CHK_VIN2_OV_CHK  ((uint32_t)0x01U << 6U)

#define BM_FUNC_STAT_CHK_VIN1_OV_CHK  ((uint32_t)0x01U << 5U)

#define BM_FUNC_STAT_CHK_VIN0_OV_CHK  ((uint32_t)0x01U << 4U)

#define BM_FUNC_STAT_CHK_VIN3_UV_CHK  ((uint32_t)0x01U << 3U)

#define BM_FUNC_STAT_CHK_VIN2_UV_CHK  ((uint32_t)0x01U << 2U)

#define BM_FUNC_STAT_CHK_VIN1_UV_CHK  ((uint32_t)0x01U << 1U)

#define BM_FUNC_STAT_CHK_VIN0_UV_CHK  ((uint32_t)0x01U << 0U)

#define FUNC_STAT_CHK_EN_OFF  0x40U

#define BM_FUNC_STAT_CHK_EN_VIN3_OV_CHK  ((uint32_t)0x01U << 7U)

#define BM_FUNC_STAT_CHK_EN_VIN2_OV_CHK  ((uint32_t)0x01U << 6U)

#define BM_FUNC_STAT_CHK_EN_VIN1_OV_CHK  ((uint32_t)0x01U << 5U)

#define BM_FUNC_STAT_CHK_EN_VIN0_OV_CHK  ((uint32_t)0x01U << 4U)

#define BM_FUNC_STAT_CHK_EN_VIN3_UV_CHK  ((uint32_t)0x01U << 3U)

#define BM_FUNC_STAT_CHK_EN_VIN2_UV_CHK  ((uint32_t)0x01U << 2U)

#define BM_FUNC_STAT_CHK_EN_VIN1_UV_CHK  ((uint32_t)0x01U << 1U)

#define BM_FUNC_STAT_CHK_EN_VIN0_UV_CHK  ((uint32_t)0x01U << 0U)

#define FUNC_CHK_INT_SIG_EN_OFF  0x44U

#define BM_FUNC_CHK_INT_SIG_EN_VIN3_OV_CHK  ((uint32_t)0x01U << 7U)

#define BM_FUNC_CHK_INT_SIG_EN_VIN2_OV_CHK  ((uint32_t)0x01U << 6U)

#define BM_FUNC_CHK_INT_SIG_EN_VIN1_OV_CHK  ((uint32_t)0x01U << 5U)

#define BM_FUNC_CHK_INT_SIG_EN_VIN0_OV_CHK  ((uint32_t)0x01U << 4U)

#define BM_FUNC_CHK_INT_SIG_EN_VIN3_UV_CHK  ((uint32_t)0x01U << 3U)

#define BM_FUNC_CHK_INT_SIG_EN_VIN2_UV_CHK  ((uint32_t)0x01U << 2U)

#define BM_FUNC_CHK_INT_SIG_EN_VIN1_UV_CHK  ((uint32_t)0x01U << 1U)

#define BM_FUNC_CHK_INT_SIG_EN_VIN0_UV_CHK  ((uint32_t)0x01U << 0U)

#define COR_ERR_INT_STAT_OFF  0x48U

#define COR_ERR_INT_STAT_EN_OFF  0x4cU

#define COR_ERR_INT_SIG_EN_OFF  0x50U

#define UNC_ERR_INT_STAT_OFF  0x54U

#define BM_UNC_ERR_INT_STAT_PWDATA_FAT_ERR  ((uint32_t)0x01U << 1U)

#define UNC_ERR_INT_STAT_EN_OFF  0x58U

#define UNC_ERR_INT_SIG_EN_OFF  0x5cU

#define REG_PARITY_ERR_INT_STAT_OFF  0x60U

#define REG_PARITY_ERR_INT_STAT_EN_OFF  0x64U

#define REG_PAR_ERR_INT_SIG_EN_OFF  0x68U

#define BM_REG_PAR_ERR_INT_SIG_EN_REG_PARITY_ERR  ((uint32_t)0x01U << 0U)

#define PRDATAINJ_OFF  0x6cU

#define PWDATA_INJ_OFF  0x70U

#define PWECC_INJ_OFF  0x74U

#define INT_ERR_INJ_OFF  0x78U

#define ANA_TEST_MD_OFF  0x7cU

#define FM_ANA_TEST_MD_VDET_TEST  ((uint32_t)0x7U << 0U)
#define FV_ANA_TEST_MD_VDET_TEST(v) \
  (((uint32_t)(v) << 0U) & FM_ANA_TEST_MD_VDET_TEST)
#define GFV_ANA_TEST_MD_VDET_TEST(v) \
  (((uint32_t)(v) & FM_ANA_TEST_MD_VDET_TEST) >> 0U)

#define ANA_STAT_DEBUG_OFF  0x80U

#define BM_ANA_STAT_DEBUG_VIN3_OV_ERR  ((uint32_t)0x01U << 15U)

#define BM_ANA_STAT_DEBUG_VIN2_OV_ERR  ((uint32_t)0x01U << 14U)

#define BM_ANA_STAT_DEBUG_VIN1_OV_ERR  ((uint32_t)0x01U << 13U)

#define BM_ANA_STAT_DEBUG_VIN0_OV_ERR  ((uint32_t)0x01U << 12U)

#define BM_ANA_STAT_DEBUG_VIN3_OV_WARN  ((uint32_t)0x01U << 11U)

#define BM_ANA_STAT_DEBUG_VIN2_OV_WARN  ((uint32_t)0x01U << 10U)

#define BM_ANA_STAT_DEBUG_VIN1_OV_WARN  ((uint32_t)0x01U << 9U)

#define BM_ANA_STAT_DEBUG_VIN0_OV_WARN  ((uint32_t)0x01U << 8U)

#define BM_ANA_STAT_DEBUG_VIN3_UV_ERR  ((uint32_t)0x01U << 7U)

#define BM_ANA_STAT_DEBUG_VIN2_UV_ERR  ((uint32_t)0x01U << 6U)

#define BM_ANA_STAT_DEBUG_VIN1_UV_ERR  ((uint32_t)0x01U << 5U)

#define BM_ANA_STAT_DEBUG_VIN0_UV_ERR  ((uint32_t)0x01U << 4U)

#define BM_ANA_STAT_DEBUG_VIN3_UV_WARN  ((uint32_t)0x01U << 3U)

#define BM_ANA_STAT_DEBUG_VIN2_UV_WARN  ((uint32_t)0x01U << 2U)

#define BM_ANA_STAT_DEBUG_VIN1_UV_WARN  ((uint32_t)0x01U << 1U)

#define BM_ANA_STAT_DEBUG_VIN0_UV_WARN  ((uint32_t)0x01U << 0U)

#define CORE_VOLTAGE_SEL_OFF  0x84U

#define BM_CORE_VOLTAGE_SEL_VAL  ((uint32_t)0x01U << 0U)
/********************************************************************************************************
 *                                      Types definition                                                *
 *******************************************************************************************************/
typedef void(* McuExt_VdNotificationPtrType)(uint32_t intStatus);


typedef enum
{
    VD_SF = 0U,
    VD_LP,
    VD_NUM
} McuExt_VdIdType;
/*vd volt_sel config type*/
typedef struct
{
    /*set vd vin0 sel thre*/
    uint8_t vin0Select;
    /*set vd vin1 sel thre*/
    uint8_t vin1Select;
    /*set vd vin2 sel thre*/
    uint8_t vin2Select;
    /*set vd vin3 sel thre*/
    uint8_t vin3Select;
} McuExt_VdVoltSelType;

/*vd threshold config type*/
typedef struct
{
    /*set vd vin0 thre*/
    uint8_t vin0Threshold;
    /*set vd vin1 thre*/
    uint8_t vin1Threshold;
    /*set vd vin2 thre*/
    uint8_t vin2Threshold;
    /*set vd vin3 thre*/
    uint8_t vin3Threshold;
} McuExt_VdThresholdType;

/*vd filter config type*/
typedef struct
{
    /*set filter sample interval*/
    uint8_t configSampleInterval;
    /*set rising edge bandwidth*/
    uint8_t configRisingFilterBandwidth;
    /*set failling edge bandwidth*/
    uint8_t configFallingFilterBandwidth;
} McuExt_VdFilterType;

typedef struct
{
    /* Read trim value from efuse */
    uint32_t efuseValue;

    /* Trim offset */
    int16_t offset;

    /* Voltage detect over voltage threshold max value */
    uint32_t upperLimit;

    /* Voltage detect under voltage threshold min value */
    uint32_t lowLimit;
} Vd_TrimConfigType;

/*vd init config type*/
typedef struct
{
    /* base address */
    uint32_t base;
    /* set VOLT_SEL */
    McuExt_VdVoltSelType voltageSelect;
    /* set ov threshold */
    McuExt_VdThresholdType ovThreshold;
    /* set uv threshold */
    McuExt_VdThresholdType uvThreshold;
    /* set filter */
    McuExt_VdFilterType filterConfig;
    /* set the interrupt status bit enable value */
    uint32_t intStaEn;
    /* set the vd interrupt notification function */
    McuExt_VdNotificationPtrType vdNotificationPtr;
    /* set the safety interrupt status bit enable value */
    uint32_t safetyIntStaEn;
} McuExt_VdCfgType;

typedef struct
{
    const McuExt_VdCfgType *vdCfgPtr;
    uint8_t vdStatus;
} McuExt_VdControllerType;
/********************************************************************************************************
 *                                      Global variables                                                *
 *******************************************************************************************************/

/********************************************************************************************************
 *                                  Global Function Declarations                                        *
 *******************************************************************************************************/
/** **************************************************************************************
 * \brief This function is used to get vd interrupt status.

 * \verbatim
 * Syntax             : uint32_t Vd_GetInterruptStatus(const McuExt_VdControllerType *localVdCfgPtr)

 * Service ID[hex]    : 0x00

 * Sync/Async         : Synchronous

 * Reentrancy         : Non reentrant

 * Parameters (in)    : vdCfgPtr - vd configuration pointer

 * Parameters (inout) : None

 * Parameters (out)   : None

 * Return value       : uint32_t - vd interrupt status

 * Description        : Get vd interrupt status
 *

 * \endverbatim
 * Traceability       : SWSR_MCU_048 SW_SM001 SW_SM006
 *****************************************************************************************/
uint32_t Vd_GetInterruptStatus(const McuExt_VdControllerType *localVdCfgPtr);

/** **************************************************************************************
 * \brief This function is used to get vd dynamic status.

 * \verbatim
 * Syntax             : uint32_t Vd_GetDynamicStatus(const McuExt_VdControllerType *localVdCfgPtr)

 * Service ID[hex]    : 0x00

 * Sync/Async         : Synchronous

 * Reentrancy         : Non reentrant

 * Parameters (in)    : vdCfgPtr - vd configuration pointer

 * Parameters (inout) : None

 * Parameters (out)   : None

 * Return value       : uint32_t - vd dynamic status

 * Description        : Get vd dynamic status
 *

 * \endverbatim
 * Traceability       : SWSR_MCU_048 SW_SM001 SW_SM006
 *****************************************************************************************/
uint32_t Vd_GetDynamicStatus(const McuExt_VdControllerType *localVdCfgPtr);

/** **************************************************************************************
 * \brief This function is used to clear vd interrupt status.

 * \verbatim
 * Syntax             : void Vd_ClearInterruptStatus(const McuExt_VdControllerType *localVdCfgPtr)

 * Service ID[hex]    : 0x00

 * Sync/Async         : Synchronous

 * Reentrancy         : Non reentrant

 * Parameters (in)    : vdCfgPtr - vd configuration pointer

 * Parameters (inout) : None

 * Parameters (out)   : None

 * Return value       : None

 * Description        : Clear vd interrupt status
 *

 * \endverbatim
 * Traceability       : SWSR_MCU_048 SW_SM001 SW_SM006
 *****************************************************************************************/
void Vd_ClearInterruptStatus(const McuExt_VdControllerType *localVdCfgPtr);

/** **************************************************************************************
 * \brief This function is used to initialize voltage detector.

 * \verbatim
 * Syntax             : lld_status_t Vd_Init(McuExt_VdControllerType *localVdCfgPtr,
 *                                            const McuExt_VdCfgType *vdCfgPtr)

 * Service ID[hex]    : 0x00

 * Sync/Async         : Synchronous

 * Reentrancy         : Non reentrant

 * Parameters (in)    : vdCfgPtr - vd configuration pointer

 * Parameters (inout) : None

 * Parameters (out)   : None

 * Return value       : VD_E_OK - Initialize voltage detector successfully
 *                      E_NOT_OK - Initialize voltage detector unsuccessfully

 * Description        : Initialize voltage detector
 *

 * \endverbatim
 * Traceability       : SWSR_MCU_048 SW_SM001 SW_SM006
 *****************************************************************************************/
lld_status_t Vd_Init(McuExt_VdControllerType *localVdCfgPtr, const McuExt_VdCfgType *vdCfgPtr);

/** **************************************************************************************
 * \brief This function is service to handle vd interrupt.

 * \verbatim
 * Syntax             : void Vd_SFIrqHandler(const McuExt_VdControllerType *localVdCfgPtr)

 * Service ID[hex]    : 0x00

 * Sync/Async         : Synchronous

 * Reentrancy         : Non reentrant

 * Parameters (in)    : None

 * Parameters (inout) : None

 * Parameters (out)   : None

 * Return value       : None

 * Description        : This function is service to handle vd interrupt.
 *
 * \endverbatim
 * Traceability       :
 *****************************************************************************************/
void Vd_SFIrqHandler(const McuExt_VdControllerType *localVdCfgPtr);

/** **************************************************************************************
 * \brief This function is service to handle vd interrupt.

 * \verbatim
 * Syntax             : void Vd_LPIrqHandler(const McuExt_VdControllerType *localVdCfgPtr)

 * Service ID[hex]    : None

 * Sync/Async         : Synchronous

 * Reentrancy         : Non reentrant

 * Parameters (in)    : None

 * Parameters (inout) : None

 * Parameters (out)   : None

 * Return value       : None

 * Description        : This function is service to handle vd interrupt.
 *
 * \endverbatim
 * Traceability       :
 *****************************************************************************************/
void Vd_LPIrqHandler(const McuExt_VdControllerType *localVdCfgPtr);

#ifdef __cplusplus
}
#endif

#endif  /* ifndef VD_H */
/* End of file */
